package org.jeecg.modules.pdd.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.commons.lang.StringUtils;
import org.jeecg.modules.mall.entity.TbMnUser;
import org.jeecg.modules.mall.service.ITbMnUserService;
import org.jeecg.modules.pdd.entity.PddPromotion;
import org.jeecg.modules.pdd.mapper.PddPromotionMapper;
import org.jeecg.modules.pdd.service.IPddPromotionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

/**
 * @Description: 拼多多推广位管理
 * @Author: jeecg-boot
 * @Date:   2020-06-02
 * @Version: V1.0
 */
@Service
public class PddPromotionServiceImpl extends ServiceImpl<PddPromotionMapper, PddPromotion> implements IPddPromotionService {

    @Autowired
    @Lazy(true)
    private ITbMnUserService tbMnUserService;
    @Override
    public PddPromotion getOneByUser_id(String user_id) {
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.eq("user_id",user_id);
        return  this.getOne(queryWrapper);
    }

    @Override
    public PddPromotion getOneByPid(String pid) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("pid", pid);
        return this.getOne(queryWrapper);
    }

    @Override
    public TbMnUser getTbmnUserByPid(String pid) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("pid", pid);
        PddPromotion pddPromotion= this.getOne(queryWrapper);
        if(null!=pddPromotion&& StringUtils.isEmpty(pddPromotion.getUserId())){
            String userId= pddPromotion.getUserId();
            return tbMnUserService.getById(userId);
        }
        return null;
    }
}
